import logging
from apscheduler.schedulers.background import BlockingScheduler
import chromadb_service

n = 0
b = 50
# 配置全局日志参数
logging.basicConfig(format='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s',
                    level=logging.INFO)


def job_fn(desc):
    global n
    logging.info(desc)
    result = chromadb_service.get_embedding(f'key-{n}')
    print(f'{desc} - {b + n}')
    chromadb_service.add2([f'key-{b + n}'], result)
    n += 1
    
    
# def job_fn2(desc):
#     logging.info(desc)


if __name__ == '__main__':
    # 创建后台执行的 schedule
    scheduler = BlockingScheduler()
    # 添加调度任
    # scheduler.add_job(job_fn2, 'cron', args=('cron',), hour=10, minute=48, second=6)
    # scheduler.add_job(job_fn,  'interval', args=(), hours=3)
    scheduler.add_job(job_fn, 'interval', args=('interval 10 seconds',), seconds=10)
    # 启动调度任务
    scheduler.start()
